package com.fang.blogsystem.mapper;

import com.fang.blogsystem.pojo.DO.Comment;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * @author Bernie_fang
 * @create 2021/5/28 17:56
 **/
@Mapper
@Repository
public interface CommentMapper {

    // 分页展示某个文章的评论
    @Select("SELECT * FROM comment WHERE article_id=#{aid} ORDER BY id DESC")
    public List<Comment> selectCommentWithPage(Integer aid);

    // 后台查询最新几条评论
    @Select("SELECT * FROM comment ORDER BY id DESC")
    public List<Comment> selectNewComment();

    // 发表评论
    @Insert("INSERT INTO comment (article_id,created,author,ip,content)" +
            " VALUES (#{articleId}, #{created},#{author},#{ip},#{content})")
    public void pushComment(Comment comment);

    // 站点服务统计，统计评论数量
    @Select("SELECT COUNT(1) FROM comment")
    public Integer countComment();

    // 通过文章id删除评论信息
    @Delete("DELETE FROM comment WHERE article_id=#{aid}")
    public void deleteCommentWithId(Integer aid);

}
